package com.vue.admin.service.common.mybatis.dialect;

import org.apache.ibatis.session.Configuration;

/**
 * @program: vue-admin-service
 * @description:
 * @author: zhangyangyang
 * @create: 2020-04-03 13:56
 **/
public class DialectFactory {
    public static String dialectClass = null;

    public static Dialect buildDialect(Configuration configuration) {
        if(DialectFactory.dialectClass == null) {
            synchronized(DialectFactory.class) {
                if(DialectFactory.dialectClass == null) {
                    DialectFactory.dialectClass = configuration.getVariables().getProperty("dialectClass");
                }
            }
        }
        Dialect dialect = null;
        try {
            dialect = (Dialect)Class.forName(DialectFactory.dialectClass).newInstance();
        } catch(Exception e) {
            e.printStackTrace();
            System.err.println("请检查 mybatis-config.xml 中  dialectClass 是否配置正确?");
        }
        return dialect;
    }
}
